{layout name="layout" /}

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    <a href="{:url('admin/index/index')}"> 首页</a>
    <span class="c-gray en">&gt;</span>
    <a href="{:url('admin/topic_content/index')}">专题信息管理</a>
    <span class="c-gray en">&gt;</span>
    <a href="javascript:void(0);">{$topicInfo.title}</a>
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
        href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>

<div class="Hui-article">
    <article class="cl pd-20">
        <div class="cl pd-5 bg-1 bk-gray">
            <span class="l">
                <a href="javascript:;" onclick="del_all('{$topicInfo.id}')" class="btn btn-danger radius">
                    <i class="Hui-iconfont">&#xe6e2;</i> 批量移除</a>
                <a class="btn btn-primary radius" href="javascript:void(0);" onclick="addTopicInfo('{$topicInfo.id}')">
                    <i class="Hui-iconfont">&#xe600;</i> 添加信息</a>
            </span>
            <span class="r">共有数据：<strong id="total">{notempty name="list"}{$list->total()}{else/}0{/notempty}</strong>
                条</span>
        </div>
        <div class="mt-10" style="min-width: 900px;">
            <table class="table table-border table-bordered table-bg">
                <thead>
                    <tr class="text-c">
                        <th width="25px;">
                            <input type="checkbox" name="allcheck" value="">
                        </th>
                        <th width="80px;">文章ID</th>
                        <th>文章专题</th>
                        <th width="120px;">栏目</th>
                        <th width="200px;">所属子专题</th>
                        <th width="120px;">排序</th>
                        <th width="200px;">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach $list as $val}
                    <tr class="text-c va-m">
                        <td>
                            <input type="checkbox" value="{$val.id}" name="checkbox[]">
                        </td>
                        <td>{$val.aid}</td>
                        <td class="text-l">
                            <a href="#" title="浏览" target="_blank">{$val.title}</a>
                        </td>
                        <td>{$val.category_name}</td>
                        <td>{$val.ts_title ?: '不属于任何子专题'}</td>
                        <td>{$val.sort}</td>
                        <td class="td-manage">
                            <a href="javascript:void(0);" title="移除" onClick="del(this,'{$val.id}')">移除</a>
                        </td>
                    </tr>
                    {/foreach}
                </tbody>
            </table>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20 ">
            <span class="r">{notempty name="list"}{$list->render()|raw}{/notempty}</span>
        </div>
    </article>
</div>
<script>
    function addTopicInfo(tid) {
        tid = tid ? parseInt(tid) : 0;
        if (tid == 0) {
            layer.msg("请选择专题", {
                icon: 5,
                time: 2000
            });
            return false;
        }
        layer_show("专题信息推送", '/admin/topic_info/articleList?tid=' + tid);
    }

    function del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.post('delete', {
                'id': id
            }, function (data) {
                if (data.code == 1) {
                    console.log($(obj));
                    $(obj).parents("tr").remove();
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 2000
                    });
                    return false;
                }
            }, 'json');
        });
    }

    function del_all(tid)
    {
        var checkbox = $('.text-c input[name="checkbox[]"]');
        var ids = new Array();
        checkbox.each(function (x) {
            if (this.checked)
                ids.push(this.value);
        })
        // console.log(ids);
        layer.confirm('确认要删除吗？', function (index) {
            $.post('delete', {
                'id': ids
            }, function (data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    }, function () {
                        // checkbox.each(function (x) {
                        //     if (this.checked)
                        //         $(this).parents("tr").remove();
                        // })
                        window.location.href="/admin/topic_info/index.html?id="+tid;
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 1000
                    });
                }
            }, 'json')
        });
    }

</script>